{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "78f514e5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x1,y1: [0.5488135  0.71518937 0.60276338] [8.46848343 8.69422083 9.24328745]\n",
      "x1,y1 reshape: (3, 1) [[0.5488135 ]\n",
      " [0.71518937]\n",
      " [0.60276338]]\n",
      "[[1.]\n",
      " [1.]\n",
      " [1.]]\n",
      "[[1.         0.5488135  8.46848343]\n",
      " [1.         0.71518937 8.69422083]\n",
      " [1.         0.60276338 9.24328745]]\n",
      "x2,y2: [0.43758721 0.891773   0.96366276] [3.27072846 3.50023981 5.1738392 ]\n",
      "[[0.         0.43758721 3.27072846]\n",
      " [0.         0.891773   3.50023981]\n",
      " [0.         0.96366276 5.1738392 ]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "np.random.seed(0) \n",
    "\n",
    "data_count = 3\n",
    "w,b = 5,3\n",
    "x1 = np.random.rand(data_count)\n",
    "y1 = w*x1 + b + np.random.rand(data_count)*5\n",
    "print(\"x1,y1:\",x1,y1)\n",
    "print(\"x1,y1 reshape:\", x1.reshape((-1, 1)).shape, x1.reshape((-1, 1)))\n",
    "\n",
    "x1 = x1.reshape((-1, 1))\n",
    "y1 = y1.reshape((-1, 1))\n",
    "label_1 = np.ones_like(x1)\n",
    "print(label_1)\n",
    "\n",
    "print(np.concatenate((label_1,x1,y1),axis=1))\n",
    "\n",
    "\n",
    "x2 = np.random.rand(3)\n",
    "y2 = w*x2 + b - np.random.rand(data_count)*5\n",
    "print(\"x2,y2:\",x2,y2)\n",
    "\n",
    "x0 = x2.reshape((-1, 1))\n",
    "y0 = y2.reshape((-1, 1))\n",
    "label_0 = np.zeros_like(x0)\n",
    "\n",
    "print(np.concatenate((label_0,x0,y0),axis=1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1e1ccf46",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3,) [0.56804456 0.92559664 0.07103606]\n",
      "(3, 1) [[6.2758693 ]\n",
      " [7.72907518]\n",
      " [7.51827952]]\n",
      "(3, 1)\n",
      "(3,) [0.77815675 0.87001215 0.97861834]\n",
      "(3, 1) [[10.88657658]\n",
      " [ 9.65745755]\n",
      " [11.79573759]]\n",
      "(3, 1)\n",
      "[[ 0.          0.56804456  6.2758693 ]\n",
      " [ 0.          0.92559664  7.72907518]\n",
      " [ 0.          0.07103606  7.51827952]\n",
      " [ 1.          0.77815675 10.88657658]\n",
      " [ 1.          0.87001215  9.65745755]\n",
      " [ 1.          0.97861834 11.79573759]]\n",
      "[[ 1.          0.97861834 11.79573759]\n",
      " [ 0.          0.07103606  7.51827952]\n",
      " [ 1.          0.77815675 10.88657658]\n",
      " [ 1.          0.87001215  9.65745755]\n",
      " [ 0.          0.92559664  7.72907518]\n",
      " [ 0.          0.56804456  6.2758693 ]]\n"
     ]
    }
   ],
   "source": [
    "def generate_data(w,b,data_count,labels=0):\n",
    "    x = np.random.rand(data_count)\n",
    "    print(x.shape,x)\n",
    "    y = (w*x + b + np.random.rand(data_count)*5).reshape((-1, 1)) \n",
    "    print(y.shape,y)\n",
    "#     x = x.reshape((-1, 1))\n",
    "    label = np.ones_like(y) if labels==1 else np.zeros_like(y)\n",
    "    print(label.shape)\n",
    "    return np.concatenate((label,np.reshape(x,(-1, 1)),y),axis=1)\n",
    "\n",
    "data1 = generate_data(w,b,data_count,0)\n",
    "data2 = generate_data(w,b,data_count,1)\n",
    "data_all = np.concatenate((data1,data2),axis=0)\n",
    "print(data_all)\n",
    "np.random.shuffle(data_all)\n",
    "print(data_all)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f9854fb4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3, 1) [[0.75861562]\n",
      " [0.10590761]\n",
      " [0.47360042]]\n",
      "(3, 1) [[7.72473984]\n",
      " [7.21412892]\n",
      " [6.45075387]]\n",
      "[[0.75861562 7.72473984]\n",
      " [0.10590761 7.21412892]\n",
      " [0.47360042 6.45075387]]\n"
     ]
    }
   ],
   "source": [
    "x2 = np.random.rand(data_count).reshape((-1, 1))\n",
    "print(x2.shape,x2)\n",
    "y2 = (w*x2 + b + (np.random.rand(data_count)*5).reshape(-1, 1))\n",
    "print(y2.shape,y2)\n",
    "print(np.concatenate((x2,y2),axis=1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a498b7f6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.2030113494607831\n",
      "0.2030113494607831\n"
     ]
    }
   ],
   "source": [
    "x = np.random.rand(data_count)\n",
    "ret1 = np.sum(x) / x.shape[0]\n",
    "print(ret1)\n",
    "ret2 = np.mean(x)\n",
    "print(ret1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6fb3b833",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3.0, 4.0]\n",
      "[0. 0. 0. 1.]\n",
      "[0. 0. 0. 1.]\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "a = ['1','2']\n",
    "b = list(map(lambda x:x+2, map(float,a)))\n",
    "print(b)\n",
    "\n",
    "x = np.zeros(4)\n",
    "x[3]=1\n",
    "print(x)\n",
    "\n",
    "t = np.zeros(4)\n",
    "t[3]=1\n",
    "print(t)\n",
    "\n",
    "t = np.zeros(4)[3]=1\n",
    "print(t) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "321d6c01",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
